﻿function timer(obj, txt) {
    obj.text(txt);
}
function showTime() {
    var today = new Date();
    var weekday = new Array(7)
    weekday[0] = "星期一"
    weekday[1] = "星期二"
    weekday[2] = "星期三"
    weekday[3] = "星期四"
    weekday[4] = "星期五"
    weekday[5] = "星期六"
    weekday[6] = "星期日"
    var y = today.getFullYear() + "年";
    var month = today.getMonth() + "月";
    var td = today.getDate() + "日";
    var d = weekday[today.getDay()];
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    timer($("#top_time_Y"), y);
    timer($("#top_time_MH"), month);
    timer($("#top_time_TD"), td);
    //timer($("#top_time_D"), d);
    timer($("#top_time_H"), h);
    timer($("#top_time_M"), m);
    timer($("#top_time_S"), s);
}

function addTab(id, title, url) {
    if ($('#tabs').tabs('exists', id)) {
        $('#tabs').tabs('select', id); //选中并刷新
    } else {
        var content = createFrame(url);
        $('#tabs').tabs('add', {
            title: title,
            id: id,
            content: content,
            closable: true
        });
    }
}
function closeTab(id) {
    $('#tabs').tabs('close', id);
}

function closeSelectedTab() {
    var id = $('#tabs').tabs('getSelected').attr('id');
    closeTab(id);
}

function selectTab(id) {
    $('#tabs').tabs('select', id);
}


function createFrame(url) {
    var s = '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>';
    return s;
}


//加载菜单
function bindmenu() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        //urlType: "QueryMenuList",
        urlType: "GetUserMenuList",
        success: function (data) {

            if (data && data.length > 0) {
                var _html = [];
                for (var i = 0; i < data.length; i++) {

                    if (data[i].PARENTID == '0') {
                        if (lang.SysLanguage == "en") {
                            _html.push('<div title="' + data[i].ENMENU_NAME + '"  style="padding:10px">');
                        }
                        else {
                            _html.push('<div title="' + data[i].MENU_NAME + '"  style="padding:10px">');
                        }

                        var _subhtml = [];
                        getsubmenu(data, data[i].MENU_ID, _subhtml);
                        _html.push(_subhtml.join('') + '</div>');
                    }


                }
                $('#menu_list').html(_html.join(''));
                $('#menu_list').accordion({ animate: false, fit: true, border: false });
                $('#menu_list div[onclick]:eq(0)').click();
            }
        }
    });

    function getsubmenu(data,parent_menuid,_html) {
        if (data && data.length > 0) { 
            for(var i=0;i<data.length;i++){
                if (data[i].PARENTID == parent_menuid && data[i].MENU_TYPE == '2') {
                    if (lang.SysLanguage == "en") {
                        _html.push('<div class="submenu" title="' + data[i].ENMENU_NAME + '" onclick="addTab(\'m_' + data[i].MENU_ID + '\', \'' + data[i].ENMENU_NAME + '\', \'' + data[i].NAVIGATEURL + '\');">' + data[i].ENMENU_NAME + '</div>');
                    }
                    else {
                        _html.push('<div class="submenu" title="' + data[i].MENU_NAME + '" onclick="addTab(\'m_' + data[i].MENU_ID + '\', \'' + data[i].MENU_NAME + '\', \'' + data[i].NAVIGATEURL + '\');">' + data[i].MENU_NAME + '</div>');
                    }
                   // getsubmenu(data,data[i].MENU_ID,_html);
                }
            }

        }
        return _html;
    }

}

//退出
function logout() {
    //    $.ajax({
    //        url: App_Config.TadongUrl + "/Logoutauth.aspx",
    //        type: 'post',
    //        dataType: 'json',
    //        data: { "data": $.oemCookie() },
    //        success: function () {
    //            $.cookieClear();
    //            location.href = App_Config.CurrentUrl+ "/login.html";
    //        }
    //    });

//    if (confirm("您确定要关闭本页吗？")) {
        window.opener = null;
        window.open('', '_self');
        window.close();
//    }
//    else { }

 

}